package com.eportal.filter;


import java.io.IOException;
import java.util.Iterator;
import java.util.Map;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

import com.eportal.domain.Sysopt;
import com.eportal.util.WebUtil;

public class UrlFilter implements Filter {

    private Logger log = Logger.getLogger(this.getClass().getName());


    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
    	
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    	try {
			HttpServletRequest req = (HttpServletRequest)request;
			HttpServletResponse resp = (HttpServletResponse) response;
			String serverName = req.getServerName();
			if(req.getRequestURI()==null||"".equals(req.getRequestURI())||"/".equals(req.getRequestURI())){
				//针对不同的域名跳转到不同的首页
				if(AuthenticationFilter.SERVER_NAME_LOCK.equals(serverName)){
	        		resp.sendRedirect(AuthenticationFilter.LOGIN_URL_LOCK);	
	        	}else if(AuthenticationFilter.SERVER_NAME_COMMUNITY.equals(serverName)){
	        		resp.sendRedirect(AuthenticationFilter.LOGIN_URL_COMMUNITY);
	        	}
			}
		} catch (Exception e) {
			log.error(this, e);
		}
		chain.doFilter(request, response);
    }
   
    @Override
    public void destroy() {

    }
}
